home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Source Code / Visual Basic Source Code.iso / vbsource / loansh_1 / loan.frm (.txt) next >
Encoding:
Visual Basic Form  |  1999-07-19  |  23.7 KB  |  712 lines

  1. VERSION 5.00
  2. Object = "{5E9E78A0-531B-11CF-91F6-C2863C385E30}#1.0#0"; "MSFLXGRD.OCX"
  3. Begin VB.Form LoanSheet 
  4.    Appearance      =   0  'Flat
  5.    BackColor       =   &H00C0C0C0&
  6.    BorderStyle     =   3  'Fixed Dialog
  7.    Caption         =   "LoanSheet"
  8.    ClientHeight    =   6975
  9.    ClientLeft      =   1230
  10.    ClientTop       =   1845
  11.    ClientWidth     =   9915
  12.    ClipControls    =   0   'False
  13.    BeginProperty Font 
  14.       Name            =   "Verdana"
  15.       Size            =   8.25
  16.       Charset         =   0
  17.       Weight          =   400
  18.       Underline       =   0   'False
  19.       Italic          =   0   'False
  20.       Strikethrough   =   0   'False
  21.    EndProperty
  22.    ForeColor       =   &H80000008&
  23.    LinkTopic       =   "Form1"
  24.    MaxButton       =   0   'False
  25.    PaletteMode     =   1  'UseZOrder
  26.    ScaleHeight     =   6975
  27.    ScaleWidth      =   9915
  28.    Begin VB.CheckBox Check1 
  29.       Caption         =   "Pay Extra Amount"
  30.       Height          =   255
  31.       Left            =   240
  32.       TabIndex        =   24
  33.       Top             =   1260
  34.       Value           =   1  'Checked
  35.       Width           =   1935
  36.    End
  37.    Begin VB.Frame Frame2 
  38.       Height          =   1875
  39.       Left            =   120
  40.       TabIndex        =   19
  41.       Top             =   1260
  42.       Width           =   2775
  43.       Begin VB.TextBox txtExtraPay 
  44.          Alignment       =   1  'Right Justify
  45.          Height          =   315
  46.          Left            =   1920
  47.          TabIndex        =   23
  48.          Text            =   "1500"
  49.          Top             =   1440
  50.          Width           =   675
  51.       End
  52.       Begin VB.OptionButton Option1 
  53.          Caption         =   "Pay fixed amount over P + I"
  54.          Height          =   435
  55.          Index           =   1
  56.          Left            =   120
  57.          TabIndex        =   21
  58.          Top             =   840
  59.          Value           =   -1  'True
  60.          Width           =   2235
  61.       End
  62.       Begin VB.OptionButton Option1 
  63.          Caption         =   "Extra Payment each month"
  64.          Height          =   435
  65.          Index           =   0
  66.          Left            =   120
  67.          TabIndex        =   20
  68.          Top             =   360
  69.          Width           =   2055
  70.       End
  71.       Begin VB.Label Label1 
  72.          Caption         =   "Pay Fixed Amount:"
  73.          Height          =   315
  74.          Left            =   120
  75.          TabIndex        =   22
  76.          Top             =   1500
  77.          Width           =   1695
  78.       End
  79.    End
  80.    Begin VB.Frame Frame1 
  81.       Caption         =   "Info"
  82.       Height          =   1215
  83.       Left            =   3120
  84.       TabIndex        =   18
  85.       Top             =   5700
  86.       Width           =   6735
  87.       Begin VB.Label lblinfo 
  88.          Caption         =   "lblinfo"
  89.          Height          =   855
  90.          Left            =   120
  91.          TabIndex        =   25
  92.          Top             =   240
  93.          Width           =   6375
  94.       End
  95.    End
  96.    Begin MSFlexGridLib.MSFlexGrid grdPayments 
  97.       Height          =   5115
  98.       Left            =   3060
  99.       TabIndex        =   14
  100.       Top             =   420
  101.       Width           =   6855
  102.       _ExtentX        =   12091
  103.       _ExtentY        =   9022
  104.       _Version        =   393216
  105.       Rows            =   50
  106.       Cols            =   6
  107.       WordWrap        =   -1  'True
  108.       AllowUserResizing=   1
  109.       FormatString    =   ""
  110.       BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
  111.          Name            =   "Arial"
  112.          Size            =   8.25
  113.          Charset         =   0
  114.          Weight          =   400
  115.          Underline       =   0   'False
  116.          Italic          =   0   'False
  117.          Strikethrough   =   0   'False
  118.       EndProperty
  119.    End
  120.    Begin VB.CommandButton cmdCalcAmort 
  121.       Appearance      =   0  'Flat
  122.       BackColor       =   &H80000005&
  123.       Caption         =   "Show Amortization"
  124.       Enabled         =   0   'False
  125.       Height          =   375
  126.       Left            =   240
  127.       TabIndex        =   13
  128.       Top             =   6480
  129.       Width           =   2295
  130.    End
  131.    Begin VB.CommandButton cmdCalcPmts 
  132.       Appearance      =   0  'Flat
  133.       BackColor       =   &H80000005&
  134.       Caption         =   "Show Payments"
  135.       Default         =   -1  'True
  136.       Height          =   375
  137.       Left            =   240
  138.       TabIndex        =   5
  139.       Top             =   5985
  140.       Width           =   2295
  141.    End
  142.    Begin VB.Frame frmLoanLen 
  143.       Caption         =   "Years in Loan"
  144.       Height          =   1335
  145.       Left            =   120
  146.       TabIndex        =   10
  147.       Top             =   3180
  148.       Width           =   2775
  149.       Begin VB.TextBox txtLen1 
  150.          Height          =   285
  151.          Left            =   1440
  152.          TabIndex        =   3
  153.          Top             =   360
  154.          Width           =   615
  155.       End
  156.       Begin VB.TextBox txtLen2 
  157.          Height          =   285
  158.          Left            =   1440
  159.          TabIndex        =   4
  160.          Top             =   840
  161.          Width           =   615
  162.       End
  163.       Begin VB.Label lblLen 
  164.          Caption         =   "Length 1:"
  165.          Height          =   255
  166.          Index           =   0
  167.          Left            =   240
  168.          TabIndex        =   12
  169.          Top             =   390
  170.          Width           =   855
  171.       End
  172.       Begin VB.Label lblLen 
  173.          Caption         =   "Length 2:"
  174.          Height          =   255
  175.          Index           =   1
  176.          Left            =   240
  177.          TabIndex        =   11
  178.          Top             =   840
  179.          Width           =   855
  180.       End
  181.    End
  182.    Begin VB.TextBox txtDwnPay 
  183.       Alignment       =   1  'Right Justify
  184.       Height          =   315
  185.       Left            =   1200
  186.       TabIndex        =   2
  187.       Text            =   "10"
  188.       Top             =   720
  189.       Width           =   1395
  190.    End
  191.    Begin VB.Frame frmIntr 
  192.       Caption         =   "Interest Rates (%)"
  193.       Height          =   1275
  194.       Left            =   120
  195.       TabIndex        =   6
  196.       Top             =   4620
  197.       Width           =   2775
  198.       Begin VB.TextBox txtRate2 
  199.          Height          =   285
  200.          Left            =   1380
  201.          TabIndex        =   17
  202.          Text            =   "8.0"
  203.          Top             =   840
  204.          Width           =   675
  205.       End
  206.       Begin VB.TextBox txtRate1 
  207.          Height          =   315
  208.          Left            =   1380
  209.          TabIndex        =   16
  210.          Text            =   "6.5"
  211.          Top             =   360
  212.          Width           =   675
  213.       End
  214.       Begin VB.Label lblIntr 
  215.          Caption         =   "Rate 2:"
  216.          BeginProperty Font 
  217.             Name            =   "Arial"
  218.             Size            =   8.25
  219.             Charset         =   0
  220.             Weight          =   400
  221.             Underline       =   0   'False
  222.             Italic          =   0   'False
  223.             Strikethrough   =   0   'False
  224.          EndProperty
  225.          Height          =   255
  226.          Index           =   1
  227.          Left            =   240
  228.          TabIndex        =   8
  229.          Top             =   885
  230.          Width           =   1095
  231.       End
  232.       Begin VB.Label lblIntr 
  233.          Caption         =   "Rate 1:"
  234.          BeginProperty Font 
  235.             Name            =   "Arial"
  236.             Size            =   8.25
  237.             Charset         =   0
  238.             Weight          =   400
  239.             Underline       =   0   'False
  240.             Italic          =   0   'False
  241.             Strikethrough   =   0   'False
  242.          EndProperty
  243.          Height          =   255
  244.          Index           =   0
  245.          Left            =   240
  246.          TabIndex        =   7
  247.          Top             =   405
  248.          Width           =   1095
  249.       End
  250.    End
  251.    Begin VB.TextBox txtPurchTotl 
  252.       Alignment       =   1  'Right Justify
  253.       Height          =   315
  254.       Left            =   1200
  255.       TabIndex        =   1
  256.       Text            =   "180000"
  257.       Top             =   120
  258.       Width           =   1395
  259.    End
  260.    Begin VB.Label Label2 
  261.       Height          =   315
  262.       Left            =   3060
  263.       TabIndex        =   15
  264.       Top             =   60
  265.       Width           =   6615
  266.    End
  267.    Begin VB.Label lblDwnPay 
  268.       Caption         =   "Percent Down"
  269.       Height          =   435
  270.       Left            =   120
  271.       TabIndex        =   9
  272.       Top             =   720
  273.       Width           =   900
  274.    End
  275.    Begin VB.Label lblPurchTotl 
  276.       Caption         =   "Purchase Amount"
  277.       Height          =   435
  278.       Left            =   120
  279.       TabIndex        =   0
  280.       Top             =   120
  281.       Width           =   900
  282.    End
  283.    Begin VB.Menu mnuOptions 
  284.       Caption         =   "&Options"
  285.       Begin VB.Menu mnuOptInstruct 
  286.          Caption         =   "&Instructions..."
  287.       End
  288.       Begin VB.Menu mnuOptSep 
  289.          Caption         =   "-"
  290.       End
  291.       Begin VB.Menu mnuOptExit 
  292.          Caption         =   "E&xit"
  293.       End
  294.    End
  295.    Begin VB.Menu mnuDwnPay 
  296.       Caption         =   "&Down Payment"
  297.       Begin VB.Menu mnuOptDwn 
  298.          Caption         =   "&Percent Down"
  299.          Checked         =   -1  'True
  300.          Index           =   0
  301.       End
  302.       Begin VB.Menu mnuOptDwn 
  303.          Caption         =   "&Amount Down"
  304.          Index           =   1
  305.       End
  306.    End
  307.    Begin VB.Menu mnuLoanLen 
  308.       Caption         =   "&Loan Length"
  309.       Begin VB.Menu mnuOptLen 
  310.          Caption         =   "&Years"
  311.          Checked         =   -1  'True
  312.          Index           =   0
  313.       End
  314.       Begin VB.Menu mnuOptLen 
  315.          Caption         =   "&Months"
  316.          Index           =   1
  317.       End
  318.    End
  319. Attribute VB_Name = "LoanSheet"
  320. Attribute VB_GlobalNameSpace = False
  321. Attribute VB_Creatable = False
  322. Attribute VB_PredeclaredId = True
  323. Attribute VB_Exposed = False
  324. Option Explicit
  325. ' Form variables for purchase/down payment
  326. Dim PurchAmt As Double
  327. Dim DPAmt As Double
  328. ' Form variable for loan amount
  329. Dim LoanAmt As Double
  330. 'Array for payments
  331. Dim Payments(1 To 2, 1 To 2) As Double
  332. ' Array for amortization information
  333. Dim AmortData() As Double
  334. ' Form variable to hold payment for amortization calculation
  335. Dim AmortPmnt As Double
  336. ' Form variable flag telling if the grid shows amortization
  337. Dim AmortFlag
  338. 'New variables added
  339. Dim Rates(1 To 2) As Double
  340. Dim Length(1 To 2) As Double
  341. Dim ExtraPay As Double
  342. Private Sub CalcAmort()
  343.     ' Declare local variables
  344.     Dim i As Integer
  345.     Dim IntrTotl As Double
  346.     Dim Months As Integer
  347.     Dim Interest As Double
  348.     Dim TotalInt As Double, TotalIntExtraPay As Double
  349.     ' Save monthly payment from selected cell
  350.     AmortPmnt = Payments(grdPayments.Row, grdPayments.Col)
  351.     ExtraPay = Val(txtExtraPay)
  352.     If Check1.Value <> 1 Then
  353.       ExtraPay = 0
  354.     Else
  355.       If Option1(1).Value = True Then
  356.         If AmortPmnt > ExtraPay Then
  357.           MsgBox "The amount to pay must be greater than the initial principal and Interest"
  358.           txtExtraPay.SetFocus
  359.           Exit Sub
  360.         End If
  361.       End If
  362.     End If
  363.         
  364.     ' Save interest rate from selected row
  365.     Interest = Rates(grdPayments.Row)
  366.     ' If the periods = years
  367.     If mnuOptLen(0).Checked = True Then
  368.         ' Make loan length loan match selected cell
  369.         Months = Length(grdPayments.Col) * 12
  370.     Else
  371.         Months = Length(grdPayments.Col)
  372.     End If
  373.     ' Size array holding amortization data
  374.     ReDim AmortData(1 To Months, 1 To 5)
  375.     ' Save original loan amount to calculate remaining principal
  376.     AmortData(1, 1) = LoanAmt
  377.     ' For each month in loan period
  378.     'Go through calculation once to get the total interest paid, if an extra payment is
  379.     'being made
  380.     TotalInt = 0
  381.     For i = 2 To Months
  382.       ' Calculate interest paid for current month
  383.       AmortData(i - 1, 2) = AmortData(i - 1, 1) * Interest / 1200
  384.       TotalInt = TotalInt + AmortData(i - 1, 2)
  385.       ' Calculate remaining balance of principal and subtract the extra payment
  386.       AmortData(i, 1) = AmortData(i - 1, 1) - AmortPmnt + AmortData(i - 1, 2)
  387.     Next i
  388.     If ExtraPay <> 0 Then
  389.       For i = 2 To Months
  390.         ' Calculate interest paid for current month
  391.         AmortData(i - 1, 2) = AmortData(i - 1, 1) * Interest / 1200
  392.         TotalIntExtraPay = TotalIntExtraPay + AmortData(i - 1, 2)
  393.         
  394.         ' Calculate remaining balance of principal and subtract the extra payment
  395.         If AmortData(i - 1, 1) > AmortPmnt Then
  396.           If Option1(1).Value And ExtraPay <> 0 Then
  397.             AmortData(i, 1) = AmortData(i - 1, 1) - AmortPmnt + AmortData(i - 1, 2) - (ExtraPay - AmortPmnt)
  398.           Else
  399.             AmortData(i, 1) = AmortData(i - 1, 1) - AmortPmnt + AmortData(i - 1, 2) - ExtraPay
  400.           End If
  401.         Else
  402.           AmortData(i, 1) = 0   'The loan has been paid off
  403.         End If
  404.         
  405.       Next i
  406.     End If
  407.     'Show the results
  408.     grdPayments.Clear
  409.     ' Set # of non-fixed cols (4)
  410.     grdPayments.Cols = 6
  411.     grdPayments.TextMatrix(0, 0) = "P + I " & Format$(AmortPmnt, "Currency")
  412.     grdPayments.ColWidth(0) = 1.1 * TextWidth("000000")
  413.             
  414.     ' Set remaining col headings
  415.     grdPayments.TextMatrix(0, 1) = "Principal Paid"
  416.     grdPayments.TextMatrix(0, 2) = "Interest Paid"
  417.     grdPayments.TextMatrix(0, 3) = "Principal Balance"
  418.     grdPayments.TextMatrix(0, 4) = "Total Interest to Date"
  419.     If Option1(0).Value Then
  420.       grdPayments.TextMatrix(0, 5) = "Extra Payment"
  421.     Else
  422.       grdPayments.TextMatrix(0, 5) = "Fixed Payment above P+I"
  423.     End If
  424.     grdPayments.RowHeight(0) = 500
  425.         
  426.     ' Display vert scroll bar
  427.     grdPayments.ScrollBars = 3
  428.     ' Set # of non-fixed rows
  429.     If Months > 16 Then
  430.         grdPayments.Rows = Months + 1
  431.     Else
  432.         grdPayments.Rows = 16
  433.     End If
  434.     For i = 1 To Months
  435.         grdPayments.TextMatrix(i, 0) = i
  436.     Next i
  437.     For i = 1 To 5
  438.        grdPayments.ColWidth(i) = 1.1 * TextWidth("0000000.00")
  439.     Next i
  440.     ' Set initial interest total
  441.     IntrTotl = 0
  442.     ' Put values of non-fixed rows in grid
  443.     For i = 1 To Months
  444.       If AmortData(i, 1) > 0 Then
  445.         'Display part of payment applied to principal
  446.         grdPayments.TextMatrix(i, 1) = Format$(AmortPmnt - AmortData(i, 2), "Currency")
  447.         ' Display interest paid this payment in 2nd non-fixed col
  448.         grdPayments.TextMatrix(i, 2) = Format$(AmortData(i, 2), "Currency")
  449.         ' Display balance remaining on principal in 3rd non-fixed col
  450.         grdPayments.TextMatrix(i, 3) = Format$(AmortData(i, 1), "Currency")
  451.         ' Display total interest paid to date in last non-fixed col
  452.         IntrTotl = IntrTotl + AmortData(i, 2)
  453.         grdPayments.TextMatrix(i, 4) = Format$(IntrTotl, "Currency")
  454.         grdPayments.TextMatrix(i, 5) = Format$(ExtraPay, "Currency")
  455.       Else
  456.         grdPayments.TextMatrix(i, 1) = "Paid Off"
  457.       End If
  458.     Next i
  459.     ' Disable Calculate Amortization button
  460.     cmdCalcAmort.Enabled = False
  461.     ' Enable amortization flag
  462.     AmortFlag = True
  463.     lblinfo = "Loan Amount = " & Format(LoanAmt, "Currency") & Chr(13) & Chr(10)
  464.     lblinfo = lblinfo & "Total Interest Paid = " & Format(TotalInt, "Currency") & " (no extra payment)" & Chr(13) & Chr(10)
  465.     If ExtraPay <> 0 Then
  466.       lblinfo = lblinfo & "Total Interest Paid = " & Format(TotalIntExtraPay, "Currency") & " (with extra payment)" & Chr(13) & Chr(10)
  467.       lblinfo = lblinfo & "Amount saved with Extra Payment = " & Format(TotalInt - TotalIntExtraPay, "Currency") & Chr(13) & Chr(10)
  468.     End If
  469.         
  470. End Sub
  471. Private Sub CalcPmnts()
  472.     ' Declare local variables
  473.     Dim i As Integer
  474.     Dim j As Integer
  475.     Dim LengthUnit As String
  476.        
  477.     'calculate payments
  478.     If mnuOptLen(0).Checked = True Then
  479.       LengthUnit = "Years"
  480.     Else
  481.       LengthUnit = "Months"
  482.     End If
  483.         
  484.     For i = 1 To 2
  485.       For j = 1 To 2
  486.         If Rates(i) <> 0 And Length(j) <> 0 Then
  487.           If mnuOptLen(0).Checked = True Then 'Years
  488.             Payments(i, j) = MonthPay(Rates(i) / 1200, Length(j) * 12)
  489.           Else
  490.             Payments(i, j) = MonthPay(Rates(i) / 1200, Length(j))
  491.           End If
  492.         Else
  493.           Payments(i, j) = 0
  494.         End If
  495.       Next j
  496.     Next i
  497.           
  498.    'Now show the payments on the grid
  499.       
  500.      grdPayments.Clear
  501.       
  502.     ' Initialize line break variable
  503.     Label2 = "Monthly payments, not including extra payment"
  504.        
  505.     ' Put col headings in 1st row
  506.     For i = 1 To 2
  507.        grdPayments.TextMatrix(0, i) = Length(i) & " " & LengthUnit
  508.     Next i
  509.     ' Center text in 1st col
  510.     grdPayments.FixedAlignment(0) = 2
  511.     ' Put row headings in 1st col
  512.     For i = 1 To 2
  513.         grdPayments.TextMatrix(i, 0) = Format(Rates(i), "0.000") & "%"
  514.     Next i
  515.     ' Fill grid with payments from array
  516.     For i = 1 To 2
  517.        For j = 1 To 2
  518.           grdPayments.ColAlignment(j) = 2
  519.           If Payments(i, j) <> 0 Then
  520.             grdPayments.TextMatrix(i, j) = Format$(Payments(i, j), "Currency")
  521.           Else
  522.             grdPayments.TextMatrix(i, j) = "N/A"
  523.           End If
  524.         Next j
  525.     Next i
  526.       
  527.      ' Set amortization flag to false
  528.     AmortFlag = False
  529.     grdPayments.Row = 1
  530. End Sub
  531. Private Sub Check1_Click()
  532.  Frame2.Enabled = (Check1.Value = 1)
  533.  Option1(0).Enabled = (Check1.Value = 1)
  534.  Option1(1).Enabled = (Check1.Value = 1)
  535.  txtExtraPay.Enabled = (Check1.Value = 1)
  536.  Label1.Enabled = (Check1.Value = 1)
  537. End Sub
  538. Private Sub cmdCalcAmort_Click()
  539.     ' Change mouse pointer to hourglass
  540.     MousePointer = 11
  541.     ' Calculate amortization
  542.     CalcAmort
  543.     ' Return mouse pointer to default
  544.     MousePointer = 0
  545. End Sub
  546. Private Sub cmdCalcPmts_Click()
  547.     ' Disable amortization button
  548.     cmdCalcAmort.Enabled = False
  549.     Rates(1) = Val(txtRate1)
  550.     Rates(2) = Val(txtRate2)
  551.     Length(1) = Val(Me.txtLen1)
  552.     Length(2) = Val(Me.txtLen2)
  553.     ExtraPay = Val(txtExtraPay)
  554.     PurchAmt = Val(txtPurchTotl)
  555.     DPAmt = Val(txtDwnPay)
  556.     ' Does Purchase Amount have a value?
  557.     If PurchAmt <= 0 Then
  558.         MsgBox "You must enter a valid purchase amount.", 48, "LoanSheet Error"
  559.         txtPurchTotl.Text = ""
  560.         txtPurchTotl.SetFocus
  561.         Exit Sub
  562.     End If
  563.      
  564.           
  565.     ' If maximum interest rate is less than minimum interest rate...
  566.     If Length(1) = 0 And Length(2) = 0 Then
  567.         MsgBox "You must enter at least one valid length for the loan.", 48, "LoanSheet Error"
  568.         txtRate1.SetFocus
  569.         Exit Sub
  570.     End If
  571.      
  572.      
  573.     ' If maximum interest rate is less than minimum interest rate...
  574.     If Rates(1) = 0 And Rates(2) = 0 Then
  575.         MsgBox "You must enter at least one valid interest rate.", 48, "LoanSheet Error"
  576.         txtRate1.SetFocus
  577.         Exit Sub
  578.     End If
  579.     ' Calculate loan amount
  580.     If mnuOptDwn(0).Checked = True Then
  581.         LoanAmt = PurchAmt * (1 - (DPAmt / 100))
  582.     ElseIf mnuOptDwn(1).Checked = True Then
  583.         LoanAmt = PurchAmt - DPAmt
  584.     End If
  585.     ' Change mouse pointer to hourglass
  586.     MousePointer = 11
  587.     ' Calculate payments for all loan lengths/interest rates
  588.     CalcPmnts
  589.     ' Change mouse pointer to default
  590.     lblinfo = "Loan Amount = " & Format(LoanAmt, "Currency")
  591.     MousePointer = 0
  592. End Sub
  593. Private Sub Form_Load()
  594.     ' Declare local variables
  595.     Dim iRate As Double
  596.     ' Set down payment to 0
  597.     DPAmt = 0
  598.     ' Put app in center of screen
  599.     LoanSheet.Left = (Screen.Width - LoanSheet.Width) / 2
  600.     LoanSheet.Top = (Screen.Height - LoanSheet.Height) / 2
  601.     ' Put allowed interest rates in list boxes
  602.       
  603.     txtLen1 = 30
  604.     txtLen2 = 15
  605.     txtPurchTotl = 180000
  606.     lblinfo = ""
  607. End Sub
  608. Private Sub Form_Unload(Cancel As Integer)
  609.     End
  610. End Sub
  611. Private Sub grdPayments_Click()
  612.     ' Only act if cell contains a payment
  613.     If grdPayments.Text = "" Then
  614.       cmdCalcAmort.Enabled = False
  615.       Exit Sub
  616.     End If
  617.     If grdPayments.Text <> "N/A" And AmortFlag = False Then
  618.         ' Enable amortization button
  619.         cmdCalcAmort.Enabled = True
  620.     Else
  621.         ' Disable amortization button
  622.         cmdCalcAmort.Enabled = False
  623.     End If
  624. End Sub
  625. Private Sub grdPayments_DblClick()
  626.     ' Only act if cell contains a payment
  627.     If grdPayments.Text <> "" And AmortFlag = False Then
  628.         ' Enable amortization button
  629.         cmdCalcAmort.Enabled = True
  630.         ' Change mouse pointer to hourglass
  631.         MousePointer = 11
  632.         ' Calculate amortization
  633.         CalcAmort
  634.          ' Change mouse pointer to default
  635.         MousePointer = 0
  636.     Else
  637.         ' Disable amortization button
  638.         cmdCalcAmort.Enabled = False
  639.     End If
  640. End Sub
  641. Private Sub mnuOptDwn_Click(Index As Integer)
  642.     Select Case Index
  643.         Case 0
  644.             mnuOptDwn(0).Checked = True
  645.             mnuOptDwn(1).Checked = False
  646.             lblDwnPay.Caption = "Percent Down"
  647.         Case 1
  648.             mnuOptDwn(0).Checked = False
  649.             mnuOptDwn(1).Checked = True
  650.             lblDwnPay.Caption = "Amount Down"
  651.     End Select
  652. End Sub
  653. Private Sub mnuOptExit_Click()
  654.     End
  655. End Sub
  656. Private Sub mnuOptInstruct_Click()
  657.     ' Declare local variables
  658.     Dim MsgText
  659.     Dim PB
  660.     ' Initialize paragraph break variable
  661.     PB = Chr$(10) & Chr$(13) & Chr$(10) & Chr$(13)
  662.     ' Display message
  663.     MsgText = "Enter purchase amount, down payment, length of loan, and interest rates. Click the Calculate Payments button to display monthly payments in the grid on the right."
  664.     MsgText = MsgText & PB & "Select a monthly payment and click the Calculate Amortization button to display an amortization schedule for the selected interest rate and length of loan in the grid."
  665.     MsgText = MsgText & PB & "Highlight cells in the grid and select Copy from the Options menu to copy data to the Clipboard."
  666.     MsgBox MsgText, 64, "LoanSheet Instructions"
  667. End Sub
  668. Private Sub mnuOptLen_Click(Index As Integer)
  669.     Select Case Index
  670.         ' Loan length = years
  671.         Case 0
  672.             mnuOptLen(0).Checked = True
  673.             mnuOptLen(1).Checked = False
  674.             frmLoanLen.Caption = "Years in Loan"
  675.         ' Loan length = months
  676.         Case 1
  677.             mnuOptLen(0).Checked = False
  678.             mnuOptLen(1).Checked = True
  679.             frmLoanLen.Caption = "Months in Loan"
  680.     End Select
  681. End Sub
  682. Private Function MonthPay(Interest, Months)
  683.     MonthPay = LoanAmt * (Interest / (1 - (1 / ((1 + Interest) ^ Months))))
  684. End Function
  685. Private Sub txtDwnPay_Change()
  686.     ' Store number into form variable
  687.     DPAmt = Val(txtDwnPay.Text)
  688.     ' Validate that DPAmt doesn't exceed 100% or Purchase Amount
  689.     If mnuOptDwn(0).Checked = True And DPAmt > 99 Then
  690.         MsgBox "Down payment percentage cannot exceed 99 percent.", 48, "LoanSheet Error"
  691.         txtDwnPay.Text = ""
  692.         txtDwnPay.SetFocus
  693.     ElseIf mnuOptDwn(1).Checked = True And DPAmt > PurchAmt Then
  694.         MsgBox "Down payment amount cannot exceed purchase amount.", 48, "LoanSheet Error"
  695.         txtDwnPay.Text = ""
  696.         txtDwnPay.SetFocus
  697.     ElseIf DPAmt < 0 Then
  698.         MsgBox "Down payment amount must be zero or greater.", 48, "LoanSheet Error"
  699.         txtDwnPay.Text = ""
  700.         txtDwnPay.SetFocus
  701.     End If
  702. End Sub
  703. Private Sub txtPurchTotl_Change()
  704.     PurchAmt = Val(txtPurchTotl.Text)
  705. End Sub
  706. Private Sub txtRate1_Change()
  707. Rates(1) = Val(txtRate1)
  708. End Sub
  709. Private Sub txtRate2_Change()
  710. Rates(2) = Val(txtRate2)
  711. End Sub
  712.